class FormatTime {
  static String readTimestamp(String timestamp) {
    int formatTamp = int.parse(timestamp);
    var now = new DateTime.now();
    var date = new DateTime.fromMillisecondsSinceEpoch(formatTamp * 1000);
    var diff = now.difference(date);
    var time = '';
    if (diff.inSeconds <= 0 || diff.inSeconds > 0 && diff.inMinutes <= 0 ) {
      time = '刚刚';
    } else if (diff.inMinutes > 0 && diff.inHours <= 0) {
      time = diff.inMinutes.toString() + '分钟前';
    } else if (diff.inHours > 0 && diff.inDays <= 0) {
      time = diff.inHours.toString() + '小时前';
    } else if (diff.inDays > 0 && diff.inDays < 7) {
      time = diff.inDays.toString() + '天前';
    } else if (diff.inDays >= 7 && diff.inDays < 30) {
      time = (diff.inDays / 7).floor().toString() + '周前';
    } else if (diff.inDays >= 30 && diff.inDays < 365) {
      time = (diff.inDays / 30).floor().toString() + '个月前';
    } else {
      time = (diff.inDays / 365).floor().toString() + '年前';
    }
    return time;
  }
}